import type { App } from 'vue'
import VForm3 from '@/plugins/vform/lib/vform.umd.js'  //引入自定义的VForm 3库
import '@/plugins/vform/lib/vform.style.css'  //引入自定义的VForm3样式

import { getAccessToken, getTenantId } from '@/utils/auth'

interface TVForm3 {
  // 图片、文件的上传地址
  upload_url?: string,
  // 上传时的headers
  upload_headers?: ()=>any,
  // 上传时携带的参数
  upload_data?: object,
  // 上传时响应体格式处理函数模版
  upload_on_upload_success?: string,
  // 图片、文件回显时的代理路径前缀
  download_proxy_url?: string
};



export const setupVForm = (app: App<Element>) => {
  app.use<TVForm3>(VForm3, {
    upload_url: import.meta.env.VITE_API_BASEPATH + import.meta.env.VITE_UPLOAD_URL,
    upload_headers: () =>{
      return {
        Authorization: 'Bearer ' + getAccessToken(),
        'tenant-id': getTenantId()
      }
    },
    upload_data: {
      businessField: 'test'
    },
    upload_on_upload_success : "return {\n  name: file.name,\n  url: result.data\n}",
    download_proxy_url: import.meta.env.VITE_API_BASEPATH
  })
}

